package br.com.grupo7IHC.marketsearch;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import br.com.grupo7IHC.marketsearch.dao.ListaDeComprasDao;
import br.com.grupo7IHC.marketsearch.entidades.ListaDeCompras;

public class NovaListaActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_nova_lista);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.nova_lista, menu);
		return true;
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		Intent it = new Intent(NovaListaActivity.this, ListasActivity.class);
        startActivity(it);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void novaListaOkButton(View view) {
		EditText nome = (EditText) findViewById(R.id.nova_lista_nome);
		EditText data = (EditText) findViewById(R.id.nova_lista_data);
		EditText hora = (EditText) findViewById(R.id.nova_lista_hora);
		String meAvisar;
		if(((CheckBox) findViewById(R.id.nova_lista_me_avisar)).isChecked()){
			meAvisar = "true";
		}else{
			meAvisar = "false";
		}

		String[] novaLista = new String[100];
		ListaDeCompras lista = new ListaDeCompras(-1,
				nome.getText().toString(), data.getText().toString(), hora
						.getText().toString(), meAvisar, novaLista);
		
		ListaDeComprasDao dao = new ListaDeComprasDao(getBaseContext());
		dao.salvarLista(lista);
		
		Intent intent = new Intent(this, ListasActivity.class);
		startActivity(intent);

	}

	public void novaListaCancelButton(View view) {
		Toast.makeText(NovaListaActivity.this, "cancelar", Toast.LENGTH_SHORT)
				.show();
	}
}
